#include <iostream>
#include <vector>
using namespace std;

#define MAXN 500001
#define LIMIT 20

int root = 0;
int cnt = 1;
int power = 0;

// vector<int> head(MAX, 0), nxt(MAX << 1, 0), to(MAX << 1, 0);
// vector<int> deep(MAX, 0);
// vector<vector<int>> stjump(MAX, vector<int>(LIMIT, 0));

int head[MAXN];
int nxt[MAXN << 1];
int to[MAXN << 1];
int deep[MAXN];
int stjump[MAXN][LIMIT];

int log2(int n)
{
	int ans = 0;
	while ((1 << ans) <= (n >> 1)) {
		ans++;
	}

	return ans;
}

void addedge(int u, int v)
{
	nxt[cnt] = head[u];
	head[u] = cnt;
	to[cnt++] = v;
}

void dfs(int v, int parent)
{
	if (v == root) {
		deep[v] = 1;
	} else {
		deep[v] = deep[parent] + 1;
	}
	stjump[v][0] = parent;
	for (int p = 1; p <= power; p++) {
		stjump[v][p] = stjump[stjump[v][p - 1]][p - 1];
	}

	for (int e = head[v]; e; e = nxt[e]) {
		if (to[e] == parent) {
			continue;
		}
		dfs(to[e], v);
	}
}

void build()
{
	dfs(root, root);
}

int query(int a, int b)
{
	if (a == b) {
		return a;
	}

	if (deep[a] < deep[b]) {
		swap(a, b);
	}

	int k = deep[a] - deep[b], p = 0;
	while (k) {
		if (k & 1) {
			a = stjump[a][p];
		}
		p++;
		k >>= 1;
	}
	if (a == b) {
		return a;
	}

	for (int p = power; p >= 0; p--) {
		if (stjump[a][p] != stjump[b][p]) {
			a = stjump[a][p];
			b = stjump[b][p];
		}
	}

	return stjump[a][0];
}

void st_tree(int n, int m, int r)
{
	root = r;
	power = log2(n);
	for (int i = 0, u, v; i < n - 1; i++) {
		cin >> u >> v;
		addedge(u, v);
		addedge(v, u);
	}
	build();
	for (int i = 0, a, b; i < m; i++) {
		cin >> a >> b;
		cout << query(a, b) << endl;
	}
}

int main()
{
	freopen("/tmp/P3379_4.in", "r", stdin);
	int n, m, r;
	cin >> n >> m >> r;
	st_tree(n, m, r);
	return 0;
}